package com.test04_数组;

import org.junit.Test;

/**
 * 对象数组
 */
public class YootkDemo_06 {

    @Test
    public void test1() {
        Book[] books = new Book[3];
        books[0] = new Book("Java从入门到项目实战", "李兴华", 99.8);
        books[1] = new Book("Python从入门到项目实战", "李兴华", 89.8);
        books[2] = new Book("GO从入门到项目实战", "李兴华", 79.8);
        for (Book book : books) {
            System.out.println(book.getInfo());
        }
    }

    @Test
    public void test2() {
        Book bookA = new Book("Java从入门到项目实战", "李兴华", 99.8);
        Book bookB = new Book("Python从入门到项目实战", "李兴华", 89.8);
        Book[] books = new Book[]{
                bookA, bookB,
                new Book("GO从入门到项目实战", "李兴华", 79.8)
        };
        for (Book book : books) {
            System.out.println(book.getInfo());
        }
    }
}

/**
 * 图书类
 */
class Book {
    private String title;
    private String author;
    private double price;

    public Book(String title, String author, double price) {
        this.title = title;
        this.author = author;
        this.price = price;
    }

    public String getInfo() {
        return "图书名称：" + this.title + "、图书作者：" + this.author + "、图书价格：" + this.price;
    }
}
